//将选项赋值到数组中
function assignToArray(optionA,optionB,optionC,optionD,optionE,optionF){
	var array = new Array();
	var i = 0;
	if(optionA != "" && optionA != undefined){
		array[i++] = optionA;
	}
	if(optionB != "" && optionB != undefined){
		array[i++] = optionB;
	}
	if(optionC != "" && optionC != undefined){
		array[i++] = optionC;
	}
	if(optionD != "" && optionD != undefined){
		array[i++] = optionD;
	}
	if(optionE != "" && optionE != undefined){
		array[i++] = optionE;
	}
	if(optionF != "" && optionF != undefined){
		array[i++] = optionF;
	}
	return array;
}
//数组答案选项随机排序
function radomAnswerArray(array){
	var array_new = array;
	array_new.sort(function(){
		return Math.random() > 0.5 ? -1 : 1;
	});
	return array_new;
}
//数组转json
function arrayToJson(o) {
    var r = [];   
    if (typeof o == "string") 
    	return "\"" + o.replace(/([\'\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\"";   
    if (typeof o == "object") {   
    	if (!o.sort) {   
    		for (var i in o)   
			    r.push(i + ":" + arrayToJson(o[i]));   
		    if (!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)){   
		    	r.push("toString:" + o.toString.toString());   
		    }   
		    r = "{" + r.join() + "}";   
		} else {   
		    for (var i = 0; i < o.length; i++) {   
		    	r.push(arrayToJson(o[i]));   
		    }   
		    r = "[" + r.join() + "]";   
		}   
		return r;   
	}   
    return o.toString();   
}
function transOptToWords(number){
	var tmpWords = '';
	if(number == 0){
		tmpWords = "A";
	}else if(number == 1){
		tmpWords = "B";
	}else if(number == 2){
		tmpWords = "C";
	}else if(number == 3){
		tmpWords = "D";
	}else if(number == 4){
		tmpWords = "E";
	}else if(number == 5){
		tmpWords = "F";
	}
	return tmpWords;
}
function transOptToNums(myAnswer){
	var currNum = -1;
	if(myAnswer == "A"){
		currNum = 0;
	}else if(myAnswer == "B"){
		currNum = 1;
	}else if(myAnswer == "C"){
		currNum = 2;
	}else if(myAnswer == "D"){
		currNum = 3;
	}else if(myAnswer == "E"){
		currNum = 4;
	}else if(myAnswer == "F"){
		currNum = 5;
	}
	return currNum;
}
function checkLoreId(lorePath,currentLoreId){
	var pathArray = lorePath.split(":");
	for(var i = 0 ; i < pathArray.length; i++){
		var pathDetailArray = pathArray[i].split("|");
		for(var j = 0 ; j < pathDetailArray.length ; j++){
			if(currentLoreId == pathDetailArray[j]){
				if(i == 0 && j == pathDetailArray.length - 1){//本知识点--stepComplete = 1
					return true;
				}else if(i > 0 && i < pathArray.length - 1){//中间知识点--stepComplete = 0
					return false;
				}else if(i == pathArray.length - 1){//溯源最后一个知识点--stepComplete = 1
					return true;
				}
			}
		}
	}
}
export default {
	assignToArray,
	radomAnswerArray,
	arrayToJson,
	transOptToWords,
	transOptToNums,
	checkLoreId
}